﻿using MvcApplication;
using MvcApplication.service;
using MvcEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication4MVC.request;

namespace WebApplication4MVC.Controllers
{
    public class RegisterController : Controller
    {
        DemoService demoService = new DemoService();
        // GET: Register
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult SubmitReg(RegisterRequest request)
        {
            var reslt = new ResponseReslut();
            if (request==null)
            {
                return Json(new ResponseReslut() { code=400,msg="参数错误" });
            }

            if (string.IsNullOrWhiteSpace(request.UserName))
            {
                return Json(new ResponseReslut() { code = 400, msg = "用户名输入错误" });
            }

            if (string.IsNullOrWhiteSpace(request.UserPassword))
            {
                return Json(new ResponseReslut() { code = 400, msg = "用户密码输入错误" });
            }

            //我们做了一次前端传入的实体model数据和 后端数据库的实体类型转换
            DemoUser demoUser = new DemoUser();
            demoUser.UserName = request.UserName;
            demoUser.UserPassword = request.UserPassword;
            demoUser.UserPhone = request.UserPhone;

            var tempResult = demoService.addDemo(demoUser);
            //return RedirectToRoute(new { controller = "Login", action = "Index" });
            return Json(tempResult);
        }
    }
}